<template>
  <div class="divBox">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <div class="container">
          <el-form inline>
            <el-form-item :label="$t('shuJuSouSuo')">
              <el-input
                v-model="listPram.keywords"
                :placeholder="$t('tishi25')"
                class="selWidth"
                size="small"
                clearable
              >
                <el-button slot="append" icon="el-icon-search" size="small" @click="handlerSearch" />
              </el-input>
            </el-form-item>
          </el-form>
        </div>
        <el-button
          size="mini"
          type="primary"
          @click="handlerOpenEdit({}, 0)"
          v-hasPermi="['platform:config:group:save']"
          >{{ $t('tianJiaShuJuZu') }}</el-button
        >
      </div>
      <el-table
        :data="dataList.list"
        style="width: 100%; margin-bottom: 20px"
        size="mini"
        highlight-current-row
        :header-cell-style="{ fontWeight: 'bold' }"
      >
        <el-table-column :label="$t('shuJuZuMingCheng')" prop="name" min-width="150" />
        <el-table-column :label="$t('jianJie')" prop="info" min-width="150" />
        <el-table-column :label="$t('caoZuo')" fixed="right" min-width="180">
          <template slot-scope="scope">
            <el-button
              size="small"
              type="text"
              @click="handleDataList(scope.row)"
              v-hasPermi="['platform:config:group:data:list']"
              >{{ $t('shuJuLieBiao') }}</el-button
            >
            <el-button
              size="small"
              type="text"
              @click="handlerOpenEdit(scope.row, 1)"
              v-hasPermi="['platform:config:group:data:info', 'platform:config:group:data:update']"
              >{{ $t('bianJi') }}</el-button
            >
            <el-button
              size="small"
              type="text"
              @click="handleDelete(scope.row)"
              v-hasPermi="['platform:config:group:data:delete']"
              >{{ $t('shanChu') }}</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="listPram.page"
        :page-sizes="constants.page.limit"
        :page-size="listPram.limit"
        :layout="constants.page.layout"
        :total="dataList.total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>

    <el-dialog
      :title="editDialogConfig.isCreate === 0 ? $t('chuangJianShuJuZu') : $t('bianJiShuJuZu')"
      :visible.sync="editDialogConfig.visible"
    >
      <edit
        v-if="editDialogConfig.visible"
        :is-create="editDialogConfig.isCreate"
        :edit-data="editDialogConfig.editData"
        @hideDialog="handlerHideDialog"
      />
    </el-dialog>
    <el-dialog :title="$t('zuHeShuJuLieBiao')" :visible.sync="comDataListConfig.visible" fullscreen>
      <cm-data-list v-if="comDataListConfig.visible" :form-data="comDataListConfig.formData" />
    </el-dialog>
  </div>
</template>

<script>
import edit from '@/views/maintain/devconfig/combinedDataEdit';
import * as systemGroupApi from '@/api/systemGroup';
import cmDataList from './combineDataList';
export default {
  // name: "combinedData"
  components: { edit, cmDataList },
  data() {
    return {
      constants: this.$constants,
      dataList: {
        list: [],
        total: 0,
      },
      listPram: {
        keywords: null,
        page: 1,
        limit: 20,
        pageSize: this.$constants.page.limit[0],
      },
      editDialogConfig: {
        visible: false,
        isCreate: 0, // 0=创建 1=编辑
        editData: {},
      },
      comDataListConfig: {
        visible: false,
        formData: {},
      },
    };
  },
  mounted() {
    this.handlerGetList(this.listPram);
  },
  methods: {
    handlerSearch() {
      this.listPram.page = 1;
      this.handlerGetList(this.listPram);
    },
    handlerOpenEdit(editData, isCreate) {
      isCreate === 0 ? (this.editDialogConfig.editData = {}) : (this.editDialogConfig.editData = editData);
      this.editDialogConfig.isCreate = isCreate;
      this.editDialogConfig.visible = true;
    },
    handlerGetList(pram) {
      systemGroupApi.groupList(pram).then((data) => {
        this.dataList = data;
      });
    },
    handleDataList(rowData) {
      if (rowData.formId <= 0) return this.$message.error(this.$t('qingXianGuanLianBiaoDan'));
      this.comDataListConfig.formData = rowData;
      this.comDataListConfig.visible = true;
    },
    handleDelete(rowData) {
      this.$modalSure(this.$t('shanChuDangQianShuJu'), this.$t('tiShi')).then(() => {
        systemGroupApi.groupDelete(rowData).then((data) => {
          this.$message.success(this.$t('shanChuChengGong'));
          setTimeout(() => {
            this.handlerGetList(this.listPram);
          }, 800);
        });
      });
    },
    handleSizeChange(val) {
      this.listPram.limit = val;
      this.handlerGetList(this.listPram);
    },
    handleCurrentChange(val) {
      this.listPram.page = val;
      this.handlerGetList(this.listPram);
    },
    handlerHideDialog() {
      setTimeout(() => {
        this.editDialogConfig.visible = false;
        this.handlerGetList(this.listPram);
      }, 800);
    },
  },
};
</script>

<style scoped lang="scss">
.el-form-item .el-form-item {
  margin-bottom: 22px !important;
}
</style>
